import MetaTrader5 as mt5
# 显示有关MetaTrader 5程序包的数据
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
 
# 建立与MetaTrader 5程序端的连接
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()
 
# 显示有关MetaTrader 5版本的数据
print(mt5.version())
# 连接到指定密码和服务器的交易账户
account=277203715
authorized=mt5.login(account,password="WANGhou@1234",server="Exness-MT5Trial5")  # the terminal database password is applied if connection data is set to be remembered

if authorized:
    print("============登录成功========== ")
    # 显示有关连接状态、服务器名称和交易账户的数据
    print("connected to account #{}".format(account))
else:
    print("failed to connect at account #{}, error code: {}".format(account, mt5.last_error()))

# 断开与MetaTrader 5程序端的连接
mt5.shutdown()